from building import *

cwd  = GetCurrentDir()

src_pub = []
src_lib = []
path = []

sys_config = os.path.join(cwd, '..', '..', '..', 'config', 'sys_config.h')
options = LocalOptions(sys_config)

ble_lib_name = 'ble'
platform_match = 'yes'

if (GetLocalDepend(options, 'CFG_SOC_NAME') == 'SOC_BK7231U'):
    ble_lib_name += '_7231u'
elif (GetLocalDepend(options, 'CFG_SOC_NAME') == 'SOC_BK7221U'):
    ble_lib_name += '_7251'
else:
    ble_lib_name += '_unknown'
    platform_match = 'no'

if (GetLocalDepend(options, 'CFG_USE_BLE_PS') == 1):
    ble_lib_name += '_ps'

if ((GetLocalDepend(options, 'CFG_SUPPORT_BLE') == 1)
    and (GetLocalDepend(options, 'CFG_BLE_VERSION') == 'BLE_VERSION_4_2')):
    src_lib += ["beken_ble_sdk/controller/src/ea/ea.c"]
    src_lib += ["beken_ble_sdk/controller/src/em/em_buf.c"]
    src_lib += ["beken_ble_sdk/controller/src/llc/llc.c"]
    src_lib += ["beken_ble_sdk/controller/src/llc/llc_ch_asses.c"]
    src_lib += ["beken_ble_sdk/controller/src/llc/llc_hci.c"]
    src_lib += ["beken_ble_sdk/controller/src/llc/llc_llcp.c"]
    src_lib += ["beken_ble_sdk/controller/src/llc/llc_task.c"]
    src_lib += ["beken_ble_sdk/controller/src/llc/llc_util.c"]
    src_lib += ["beken_ble_sdk/controller/src/lld/lld.c"]
    src_lib += ["beken_ble_sdk/controller/src/lld/lld_evt.c"]
    src_lib += ["beken_ble_sdk/controller/src/lld/lld_pdu.c"]
    src_lib += ["beken_ble_sdk/controller/src/lld/lld_sleep.c"]
    src_lib += ["beken_ble_sdk/controller/src/lld/lld_util.c"]
    src_lib += ["beken_ble_sdk/controller/src/lld/lld_wlcoex.c"]
    src_lib += ["beken_ble_sdk/controller/src/llm/llm.c"]
    src_lib += ["beken_ble_sdk/controller/src/llm/llm_hci.c"]
    src_lib += ["beken_ble_sdk/controller/src/llm/llm_task.c"]
    src_lib += ["beken_ble_sdk/controller/src/llm/llm_util.c"]
    src_lib += ["beken_ble_sdk/hci/ahi/ahi.c"]
    src_lib += ["beken_ble_sdk/hci/ahi/ahi_task.c"]
    src_lib += ["beken_ble_sdk/hci/h4tl.c"]
    src_lib += ["beken_ble_sdk/hci/hci.c"]
    src_lib += ["beken_ble_sdk/hci/hci_fc.c"]
    src_lib += ["beken_ble_sdk/hci/hci_msg.c"]
    src_lib += ["beken_ble_sdk/hci/hci_tl.c"]
    src_lib += ["beken_ble_sdk/hci/hci_util.c"]
    src_lib += ["beken_ble_sdk/host/src/attc/attc.c"]
    src_lib += ["beken_ble_sdk/host/src/attm/attm.c"]
    src_lib += ["beken_ble_sdk/host/src/attm/attm_db.c"]
    src_lib += ["beken_ble_sdk/host/src/atts/atts.c"]
    src_lib += ["beken_ble_sdk/host/src/gapc/gapc.c"]
    src_lib += ["beken_ble_sdk/host/src/gapc/gapc_hci.c"]
    src_lib += ["beken_ble_sdk/host/src/gapc/gapc_sig.c"]
    src_lib += ["beken_ble_sdk/host/src/gapc/gapc_task.c"]
    src_lib += ["beken_ble_sdk/host/src/gapm/gapm.c"]
    src_lib += ["beken_ble_sdk/host/src/gapm/gapm_hci.c"]
    src_lib += ["beken_ble_sdk/host/src/gapm/gapm_task.c"]
    src_lib += ["beken_ble_sdk/host/src/gapm/gapm_util.c"]
    src_lib += ["beken_ble_sdk/host/src/gattc/gattc.c"]
    src_lib += ["beken_ble_sdk/host/src/gattc/gattc_task.c"]
    src_lib += ["beken_ble_sdk/host/src/gattm/gattm.c"]
    src_lib += ["beken_ble_sdk/host/src/gattm/gattm_task.c"]
    src_lib += ["beken_ble_sdk/host/src/l2cc/l2cc.c"]
    src_lib += ["beken_ble_sdk/host/src/l2cc/l2cc_lecb.c"]
    src_lib += ["beken_ble_sdk/host/src/l2cc/l2cc_pdu.c"]
    src_lib += ["beken_ble_sdk/host/src/l2cc/l2cc_sig.c"]
    src_lib += ["beken_ble_sdk/host/src/l2cc/l2cc_task.c"]
    src_lib += ["beken_ble_sdk/host/src/l2cm/l2cm.c"]
    src_lib += ["beken_ble_sdk/host/src/smpc/smpc.c"]
    src_lib += ["beken_ble_sdk/host/src/smpc/smpc_api.c"]
    src_lib += ["beken_ble_sdk/host/src/smpc/smpc_crypto.c"]
    src_lib += ["beken_ble_sdk/host/src/smpc/smpc_util.c"]
    src_lib += ["beken_ble_sdk/host/src/smpm/smpm_api.c"]
    src_lib += ["beken_ble_sdk/sys/src/co/rwble.c"]
    src_lib += ["beken_ble_sdk/sys/src/co/rwble_hl.c"]
    src_lib += ["beken_ble_sdk/sys/src/co/rwip.c"]
    src_lib += ["beken_ble_sdk/sys/src/common/common_list.c"]
    src_lib += ["beken_ble_sdk/sys/src/common/common_utils.c"]
    src_lib += ["beken_ble_sdk/sys/src/ecc_p256/ecc_p256.c"]
    src_lib += ["beken_ble_sdk/sys/src/ke/kernel.c"]
    src_lib += ["beken_ble_sdk/sys/src/ke/kernel_event.c"]
    src_lib += ["beken_ble_sdk/sys/src/ke/kernel_mem.c"]
    src_lib += ["beken_ble_sdk/sys/src/ke/kernel_msg.c"]
    src_lib += ["beken_ble_sdk/sys/src/ke/kernel_queue.c"]
    src_lib += ["beken_ble_sdk/sys/src/ke/kernel_task.c"]
    src_lib += ["beken_ble_sdk/sys/src/ke/kernel_timer.c"]
    src_lib += ["beken_ble_sdk/sys/src/nvds/nvds.c"]
    
    if (GetLocalDepend(options, 'CFG_SUPPORT_BLE_MESH') == 1):
        print 'CFG_CFG_SUPPORT_BLE_MESH'
        src_lib += ["beken_ble_sdk/mesh/src/aes/aes.c"]
        src_lib += ["beken_ble_sdk/mesh/src/aes/aes_ccm.c"]
        src_lib += ["beken_ble_sdk/mesh/src/aes/aes_cmac.c"]
        src_lib += ["beken_ble_sdk/mesh/src/aes/aes_k1.c"]
        src_lib += ["beken_ble_sdk/mesh/src/aes/aes_k2.c"]
        src_lib += ["beken_ble_sdk/mesh/src/aes/aes_k3.c"]
        src_lib += ["beken_ble_sdk/mesh/src/aes/aes_k4.c"]
        src_lib += ["beken_ble_sdk/mesh/src/aes/aes_s1.c"]
        src_lib += ["beken_ble_sdk/mesh/src/bcn/m_bcn.c"]
        src_lib += ["beken_ble_sdk/mesh/src/bearer/m_bearer.c"]
        src_lib += ["beken_ble_sdk/mesh/src/bearer/m_bearer_adv.c"]
        src_lib += ["beken_ble_sdk/mesh/src/bearer/m_bearer_gatt.c"]
        src_lib += ["beken_ble_sdk/mesh/src/common/mesh.c"]
        src_lib += ["beken_ble_sdk/mesh/src/common/mesh_log.c"]
        src_lib += ["beken_ble_sdk/mesh/src/common/mesh_tb.c"]
        src_lib += ["beken_ble_sdk/mesh/src/common/mesh_tb_buf.c"]
        src_lib += ["beken_ble_sdk/mesh/src/common/mesh_tb_sec.c"]
        src_lib += ["beken_ble_sdk/mesh/src/common/mesh_tb_timer.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_bcn.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_buf.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_data.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_friend.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_key.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_lay.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_lpn.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_mio.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_prov.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_sec.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_state.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_store.c"]
        src_lib += ["beken_ble_sdk/mesh/src/dbg/m_dbg_timer.c"]
        src_lib += ["beken_ble_sdk/mesh/src/fnd/m_fnd.c"]
        src_lib += ["beken_ble_sdk/mesh/src/fnd/m_fnd_confc.c"]
        src_lib += ["beken_ble_sdk/mesh/src/fnd/m_fnd_confs.c"]
        src_lib += ["beken_ble_sdk/mesh/src/fnd/m_fnd_hlths.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay_access.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay_friend.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay_hb.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay_lpn.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay_ltrans.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay_net.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay_proxy.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lay/m_lay_utrans.c"]
        src_lib += ["beken_ble_sdk/mesh/src/lld/lld_adv_test.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mal/mal.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mal/mal_adv.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mal/mal_con.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mal/mal_djob.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mal/mal_sec.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mal/mal_task.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mal/mal_timer.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mesh_api/mesh_api.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mesh_api/mesh_api_msg.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mesh_api/mesh_param_int.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mesh_api/mm_api.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mesh_api/mm_api_msg.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mesh_api/m_api.c"]
        src_lib += ["beken_ble_sdk/mesh/src/mesh_api/m_api_msg.c"]
        src_lib += ["beken_ble_sdk/mesh/src/prov/m_prov.c"]
        src_lib += ["beken_ble_sdk/mesh/src/prov/m_prov_adv_trans.c"]
        src_lib += ["beken_ble_sdk/mesh/src/prov/m_prov_bearer.c"]
        src_lib += ["beken_ble_sdk/mesh/src/tb/m_tb.c"]
        src_lib += ["beken_ble_sdk/mesh/src/tb/m_tb_friend.c"]
        src_lib += ["beken_ble_sdk/mesh/src/tb/m_tb_key.c"]
        src_lib += ["beken_ble_sdk/mesh/src/tb/m_tb_lpn.c"]
        src_lib += ["beken_ble_sdk/mesh/src/tb/m_tb_mio.c"]
        src_lib += ["beken_ble_sdk/mesh/src/tb/m_tb_state.c"]
        src_lib += ["beken_ble_sdk/mesh/src/tb/m_tb_store_nvds.c"]
    
    src_pub += ["ble.c"]
    src_pub += ["modules/app/src/app_ble.c"]
    src_pub += ["modules/app/src/app_comm.c"]
    src_pub += ["modules/app/src/app_sdp.c"]
    src_pub += ["modules/app/src/app_sec.c"]
    src_pub += ["modules/app/src/app_task.c"]
    src_pub += ["plactform/driver/ble_icu/ble_icu.c"]
    src_pub += ["plactform/driver/uart/ble_uart.c"]
    src_pub += ["plactform/modules/arch/ble_arch_main.c"]
    src_pub += ["plactform/modules/common/RomCallFlash.c"]
    src_pub += ["plactform/modules/dbg/dbg.c"]
    src_pub += ["plactform/modules/dbg/dbg_mwsgen.c"]
    src_pub += ["plactform/modules/dbg/dbg_swdiag.c"]
    src_pub += ["plactform/modules/dbg/dbg_task.c"]
    src_pub += ["plactform/modules/rf/src/ble_rf_xvr.c"]
    src_pub += ["profiles/comm/src/comm.c"]
    src_pub += ["profiles/comm/src/comm_task.c"]
    src_pub += ["profiles/prf/src/prf.c"]
    src_pub += ["profiles/prf/src/prf_utils.c"]
    src_pub += ["profiles/sdp/src/sdp_service.c"]
    src_pub += ["profiles/sdp/src/sdp_service_task.c"]
        
    if (GetLocalDepend(options, 'CFG_SUPPORT_BLE_MESH') == 1):
        src_lib += ["beken_ble_sdk/mesh/src/models/common/mm_route.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/common/mm_tb.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/common/mm_tb_bind.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/common/mm_tb_replay.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/common/mm_tb_state.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens_bat.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens_dtt.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens_loc.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens_lvl.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens_oo.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens_plvl.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens_poo.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/gens/mm_gens_prop.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lightc/mm_lightc.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lightc/mm_lightc_ctl.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lightc/mm_lightc_hsl.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lightc/mm_lightc_ln.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lightc/mm_lightc_xyl.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lights/mm_lights.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lights/mm_lights_ctl.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lights/mm_lights_hsl.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/lights/mm_lights_ln.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/Scenes/m_fnd_Scenes.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/transition_time/m_fnd_generic_transition_time.c"]
        src_lib += ["beken_ble_sdk/mesh/src/models/vendor/mm_vendors.c"]
        
        src_lib += ["modules/app/src/app_mesh.c"]
        src_lib += ["modules/app/src/app_mm_msg.c"]
        src_lib += ["modules/gernel_api/mesh_general_api.c"]
        src_lib += ["modules/mesh_model/ali/app_light_ali_server.c"]
    
    path += [cwd + '/']
    path += [cwd + '/beken_ble_sdk/controller/include']
    path += [cwd + '/beken_ble_sdk/hci/include']
    path += [cwd + '/beken_ble_sdk/host/include']
    path += [cwd + '/beken_ble_sdk/sys/include']
    path += [cwd + '/config']
    path += [cwd + '/modules/app/api']
    path += [cwd + '/modules/gernel_api']
    path += [cwd + '/modules/mesh_model/ali']
    path += [cwd + '/plactform/arch']
    path += [cwd + '/plactform/driver/ble_icu']
    path += [cwd + '/plactform/driver/ir']
    path += [cwd + '/plactform/driver/reg']
    path += [cwd + '/plactform/driver/sys_ctrl']
    path += [cwd + '/plactform/driver/uart']
    path += [cwd + '/plactform/include']
    path += [cwd + '/plactform/modules/include']
    path += [cwd + '/profiles/comm/api']
    path += [cwd + '/profiles/prf/include']
    path += [cwd + '/profiles/sdp/api']
    path += [cwd + '/beken_ble_sdk/mesh/include']
    path += [cwd + '/beken_ble_sdk/mesh/src/dbg']
    path += [cwd + '/beken_ble_sdk/mesh/src/models/include']

libs = [ble_lib_name]
libpath = [cwd + '/']
cppdefines = ['WIFI_BLE_COEXIST']

if (platform_match == 'yes') and (GetLocalDepend(options, 'CFG_SUPPORT_BLE') == 1):
    print 'using ble: lib' + ble_lib_name + '.a'
    group_use_lib = DefineGroup('beken_ble_pub', src_pub, CPPDEFINES = cppdefines, depend = [], CPPPATH = path, LIBS = libs, LIBPATH = libpath)
    group_build_lib = DefineGroup('beken_ble', src_lib, CPPDEFINES = cppdefines, depend = ['BUILD_LIB'], CPPPATH = path, LIBS = libs, LIBPATH = libpath, LIBNAME = 'lib' + ble_lib_name + '.a')
    group = group_use_lib + group_build_lib
else:
    group = []

Return('group')
